<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/18
 * Time: 11:41
 */

namespace Home\Controller;


class ProductController extends HomeController
{
    public $document;
    public $category;
    public function _initialize()
    {
        parent::_initialize();
        $this->document=D("document");
        $this->category=D("Category");
    }

    public function index(){
       $cate_id=118;//分类id
       $this->meta($cate_id);
       $lists=$this->document->lists($cate_id);
       foreach($lists as $key=>$val){
           $lists[$key]['son'] = $this->document->sub_document($val['id'],"id,title");
       }
       $this->assign("lists",$lists);
       $id=I("get.id",$lists[0]['son'][0]['id'],"int");
       $article_list = $this->document->sub_document_page($id,6);
       $this->assign("article_list",$article_list);
       $article_data=$this->document->detail($id);
       $this->assign("article_data",$article_data);
       $this->display();
    }
   public function detail(){
        $cate_id=118;//分类id
        $this->meta($cate_id);
        $lists=$this->document->lists($cate_id);
        foreach($lists as $key=>$val){
            $lists[$key]['son'] = $this->document->sub_document($val['id'],"id,title");
        }
        $this->assign("lists",$lists);
        $id=I("get.id",0,"int");
        $article_data = $this->document->detail($id);
        $this->assign("article_data",$article_data);
        $this->assign("id",$id);
        $this->display();
   }
    public function aluminium(){
        $cate_id=159;//分类id
        $this->meta($cate_id);
        $lists=$this->document->lists($cate_id);
        foreach($lists as $key=>$val){
            $lists[$key]['son'] = $this->document->sub_document($val['id'],"id,title");
        }
        $this->assign("lists",$lists);
        $id=I("get.id",$lists[0]['son'][0]['id'],"int");
        $article_list = $this->document->sub_document_page($id,6);
        $this->assign("article_list",$article_list);
        $article_data=$this->document->detail($id);
        $this->assign("article_data",$article_data);
        $this->display();
    }
    public function aluminium_detail(){
        $cate_id=159;//分类id
        $this->meta($cate_id);
        $lists=$this->document->lists($cate_id);
        foreach($lists as $key=>$val){
            $lists[$key]['son'] = $this->document->sub_document($val['id'],"id,title");
        }
        $this->assign("lists",$lists);
        $id=I("get.id",$lists[0]['son'][0]['id'],"int");
        $article_list = $this->document->sub_document_page($id,6);
        $this->assign("article_list",$article_list);
        $article_data=$this->document->detail($id);
        $this->assign("article_data",$article_data);
        $this->display();
    }

    public function aluminium_panel(){
        $cate_id=171;//分类id
        $this->meta($cate_id);
        $lists=$this->document->lists($cate_id);
        foreach($lists as $key=>$val){
            $lists[$key]['son'] = $this->document->sub_document($val['id'],"id,title");
        }
        $this->assign("lists",$lists);
        $id=I("get.id",$lists[0]['son'][0]['id'],"int");
        $article_list = $this->document->sub_document_page($id,6);
        $this->assign("article_list",$article_list);
        $article_data=$this->document->detail($id);
        $this->assign("article_data",$article_data);
        $this->display("");
    }
    public function aluminium_panel_detail(){
        $cate_id=171;//分类id
        $this->meta($cate_id);
        $lists=$this->document->lists($cate_id);
        foreach($lists as $key=>$val){
            $lists[$key]['son'] = $this->document->sub_document($val['id'],"id,title");
        }
        $this->assign("lists",$lists);
        $id=I("get.id",$lists[0]['son'][0]['id'],"int");
        $article_list = $this->document->sub_document_page($id,6);
        $this->assign("article_list",$article_list);
        $article_data=$this->document->detail($id);
        $this->assign("article_data",$article_data);
        $this->display("aluminium_detail");
    }
    public function search(){
        $cate_id=118;//分类id
        $this->meta($cate_id);
        $lists=$this->document->lists($cate_id);
        foreach($lists as $key=>$val){
            $lists[$key]['son'] = $this->document->sub_document($val['id'],"id,title");
        }
        $this->assign("lists",$lists);
       if(IS_POST){
           $ids=$this->document->lists(118,false,'level desc,`id` DESC',1,'id');//获取新闻动态下子文档id
           $idss='';
           foreach ($ids as $key=>$val){
               $idss.=$val['id'].',';
           }
           $search_title = I("post.search_title",0,"addslashes");
           $map=array(
               'category_id'=>118,
               'status'=>1,
               'title'=>array('like','%'.trim($search_title).'%'),
               'pid'=>array(
                    'not in',$idss
               ),
           );
           $document=M("Document");
           $p=getpage($document,$map,6);
           $list=$document->field(true)->where($map)->order('id desc')->select();
           $this->page=$p->show();
           $this->assign("list",$list);
           $this->display();
       }
    }
}